Repository navigation
Add retries and timeouts to st2client HTTP requests - #6428
Open
Vipulucc115 wants to merge 2 commits into
Open
Vipulucc115 wants to merge 2 commits into
Vipulucc115 wants to merge 2 commits into
Conversation
Failed requests to the StackStorm API are retried (3 times by default) and connecting times out after 10s instead of hanging. Connection errors are retried for every method; read timeouts and 502/503/504 only for idempotent methods, so a POST is never sent twice. Configurable via --http-retries/--http-timeout, ST2_HTTP_RETRIES/ST2_HTTP_TIMEOUT or http_retries/http_timeout in the CLI config. Part of StackStorm#3257.
|
|
1 similar comment
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes part 1 of #3257 (retry logic for
st2client).Impact:
st2commands no longer hang forever when the API can't be reached, and no longer fail on a short blip (an API restart, a load balancer answering 502/503/504). A failed request is retried up to 3 times, and connecting times out after 10 seconds. APOSTthat may already have reached the server is never sent twice, so an action can't be run twice by a retry.What changed
st2client/utils/httpclient.pyHTTPClientnow sends its requests through arequests.Sessionwith urllib3'sRetrymounted on anHTTPAdapter, as suggested in the issue.get_http_retry()):GET,PUT,DELETE,HEAD,OPTIONS), neverPOSTorPATCH.handle_error()reports it exactly as before.Retry-Afteris honoured but capped at 30s, so a proxy can't make the CLI sleep for an hour.(10, None): 10s to connect and, as today, no limit on waiting for the reply, so slow calls like pack installs aren't cut off.requests.get()calls they replace. The API'sauth-tokencookie isn't stored and resent.Settings (
client.py,models/core.py,base.py,config_parser.py,shell.py)--http-timeout/--http-retriesCLI optionsST2_HTTP_TIMEOUT/ST2_HTTP_RETRIESenvironment variableshttp_timeout/http_retriesin the[general]section of the CLI config (documented inconf/st2rc.sample.ini)Client(timeout=..., retries=...)for library users. Both are passed to every resource manager andHTTPClient, the same waycacertis.--http-retries -1,ST2_HTTP_TIMEOUT=abc, ...) fail with a clear error before any request is sent.cacert: CLI argument > config file > environment variable > default.Not in this PR
StreamManager.listen, used byst2 execution tail) still callsrequests.get(..., stream=True)directly. Retrying a long-lived stream needs different handling.st2 pack install) runs on the server side and would be a separate change.Tests
st2client/tests/unit/test_httpclient.py(25 tests). The retry tests run against a small HTTP server in a thread and count the requests it actually receives. They cover:retries=0;Retry-Afterhonoured and capped;Clientwiring and validation.requests.get/post/put/deletenow mock the same methods onrequests.Sessionand expect the defaulttimeout. The full-config fixture andtest_config_parserinclude the two new options.pytest st2client/tests/unit: 310 passed, 1 skipped (Python 3.11). black and flake8 are clean.